package models

import (
	"errors"
	"gorm.io/gorm"
	"gozero/internal/utils"
)

type User struct {
	gorm.Model
	Mobile string `gorm:"index:mobile;type:varchar(13)"`
	Passwd string `gorm:"type:varchar(64)"`
}

//验证密码有效性
func (u *User) BeforeCreate(db *gorm.DB) error {
	if len(u.Passwd) < 6 {
		return errors.New("密码长度小于6")
	}
	//对密码进行加密存储
	u.Passwd = utils.Password(u.Passwd)
	return nil
}
